﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using ClipShow2.LibraryManager;
using ClipShow2.MediaFinder;
using ClipShow2.Storage;
using ClipShow2.MediaTypes;

namespace Thumbs
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            try
            {
                StorageEngine.Initialize();
                ClipShowContent csc = StorageEngine.GetMediaLibrary(StorageEngine.MediaLibraryPath("my media"));

                foreach (ClipShowMetadata item in csc.MediaItems)
                {
                    if (!File.Exists(item.ThumbnailUrl))
                    {
                        try
                        {
                            ThumbnailCreator t = new ThumbnailCreator();
                            System.Drawing.Bitmap thumb = t.GetThumbNail(item.Url);
                            thumb.Save(item.ThumbnailUrl);
                        }
                        catch(SystemException se) 
                        {
                            System.Diagnostics.EventLog.WriteEntry("clipShow2.Thumbs.exe", se.Message);
                        }
                    }
                }
            }
            catch (SystemException se)
            {
                System.Diagnostics.EventLog.WriteEntry("clipShow2.Thumbs.exe", se.Message);
            }
            finally
            {
                this.Close();
            }
        }
    }
}
